package com.jzt.qf.task;

import com.alibaba.fastjson.JSON;
import com.jzt.qf.beans.HttpResult;
import com.jzt.qf.beans.qfBean.ZxyUploadbillJzt;
import com.jzt.qf.dao.UploadbillJztDao;
import com.jzt.qf.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
@EnableScheduling
@EnableAsync
@Slf4j
public class UploadBillTask {
    @Resource
    private UploadbillJztDao uploadbillJztDao;
    @Resource
    private BuyBillService buyBillService;

    @Scheduled(fixedDelay = 18100)
    public void uploadBuyOrderBill() {
        List<ZxyUploadbillJzt> uploadBills = uploadbillJztDao.getUploadBillByBilltype(34);
        for (ZxyUploadbillJzt uploadBill : uploadBills) {
            HttpResult httpResult = buyBillService.uoloadBuyBill(uploadBill.getBillcode());
            log.info("采购上传定时器返回数据" + JSON.toJSONString(httpResult));
        }
    }

    @Resource
    private SaleBillService saleBillService;

    @Scheduled(fixedDelay = 20100)
    public void uploadSaleBill() {
        List<ZxyUploadbillJzt> uploadBills = uploadbillJztDao.getUploadBillByBilltype(11);
        for (ZxyUploadbillJzt uploadBill : uploadBills) {
            HttpResult httpResult = saleBillService.uploadSaleBill(uploadBill.getBillcode());
            log.info("销售上传定时器返回数据" + JSON.toJSONString(httpResult));
        }
    }

    @Resource
    private BuyBackBillService buyBackBillService;

    @Scheduled(fixedDelay = 22100)
    public void uploadBuyBackBill() {
        List<ZxyUploadbillJzt> uploadBills = uploadbillJztDao.getUploadBillByBilltype(6);
        for (ZxyUploadbillJzt uploadBill : uploadBills) {
            HttpResult httpResult = buyBackBillService.uploadBuyBackBill(uploadBill.getBillcode());
            log.info("采购退货上传定时器返回数据" + JSON.toJSONString(httpResult));
        }
    }

    @Resource
    private SaleBackBillService saleBackBillService;

    @Scheduled(fixedDelay = 23100)
    public void uploadSaleBackBill() {
        List<ZxyUploadbillJzt> uploadBills = uploadbillJztDao.getUploadBillByBilltype(45);
        for (ZxyUploadbillJzt uploadBill : uploadBills) {
            HttpResult httpResult = saleBackBillService.uploadSaleBackBill(uploadBill.getBillcode());
            log.info("销售退货上传定时器返回数据" + JSON.toJSONString(httpResult));
        }
    }

    @Resource
    private OtherBillServer otherBillServer;

    @Scheduled(fixedDelay = 29100)
    public void uploadLossBill() {
        List<ZxyUploadbillJzt> uploadBills = uploadbillJztDao.getUploadBillByBilltype(9);
        for (ZxyUploadbillJzt uploadBill : uploadBills) {
            HttpResult httpResult = otherBillServer.uoloadLossBill(uploadBill.getBillcode());
            log.info("报损单定时器返回数据" + JSON.toJSONString(httpResult));
        }
    }


    @Scheduled(fixedDelay = 30100)
    public void uploadOverflowBill() {
        List<ZxyUploadbillJzt> uploadBills = uploadbillJztDao.getUploadBillByBilltype(14);
        for (ZxyUploadbillJzt uploadBill : uploadBills) {
            HttpResult httpResult = otherBillServer.uploadOverflowBill(uploadBill.getBillcode());
            log.info("报损单定时器返回数据" + JSON.toJSONString(httpResult));
        }
    }
}
